﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data;
namespace Bussiness
{
    /// <summary>
    /// 报警指导意见
    /// </summary>
    public class AlarmOperation
    {
        /// <summary>
        /// 测点号
        /// </summary>
        public string PIName { get; set; }
        /// <summary>
        /// 报警描述
        /// </summary>
        public string AlarmDescription { get; set; }
        /// <summary>
        /// 报警条件
        /// </summary>
        public string AlarmContination { get; set; }
        /// <summary>
        /// 测点参数集
        /// </summary>
        public string PointParamnet { get; set; }
        /// <summary>
        /// 指导意见
        /// </summary>
        public string OperationIdea { get; set; }
        /// <summary>
        /// 返回指导意见集
        /// </summary>
        /// <returns></returns>
        public DataTable GetAlarmOperation()
        {
            
            string sql = "SELECT * FROM ADMINISTRATOR.T_ALARM_KBS";
            if (AlarmDescription != "0" && AlarmDescription != "")
                sql = "SELECT * FROM ADMINISTRATOR.T_ALARM_KBS WHERE 报警描述='" + AlarmDescription + "'";
            DB2Provider.DataLink link = new DB2Provider.DataLink();
            DataTable dt = link.ExcuteRetureTable(sql);
            return dt;
        }
        /// <summary>
        /// 返回指导意见集
        /// </summary>
        /// <param name="alarmDescription">报警描述</param>
        /// <returns></returns>
        public DataTable GetAlarmOperation(string alarmDescription)
        {
            string sql = "SELECT * FROM ADMINISTRATOR.T_ALARM_KBS WHERE 报警描述='" + alarmDescription + "'";
            DB2Provider.DataLink link = new DB2Provider.DataLink();
            DataTable dt = link.ExcuteRetureTable(sql);
            return dt;
        }
        /// <summary>
        /// 返回指导意见集
        /// </summary>
        /// <returns></returns>
        public DataTable GetAllAlarmOperation()
        {
            string sql = "SELECT * FROM ADMINISTRATOR.T_ALARM_KBS ";
            DB2Provider.DataLink link = new DB2Provider.DataLink();
            DataTable dt = link.ExcuteRetureTable(sql);
            DataColumn col = new DataColumn();

            
            return dt;
        }
        /// <summary>
        /// 指导意见列
        /// </summary>
        /// <returns></returns>
        private DataTable GenerateOperationColumn()
        {
            System.Data.DataTable NewDT = new DataTable();

            System.Data.DataColumn col1 = new DataColumn("YJ");
            NewDT.Columns.Add(col1);
            return NewDT;
        }
        /// <summary>
        /// 返回测点集
        /// </summary>
        /// <param name="alarmPoint"></param>
        private void SplitAlarmPoint(string alarmPoint)
        {
            string[] splitAlarmPoint = alarmPoint.Split(',');
        }
        /// <summary>
        /// 返回报警点
        /// </summary>
        /// <param name="PIDeclare"></param>
        /// <returns></returns>
        //public DataTable GetAlarmPoint(PiLink.declare PIDeclare)
        //{
        //    string[] alarmPoint = new string[9999];
        //    DataTable dt = GetAlarmOperation();
        //    string paraContidination = "";
        //    System.Collections.ArrayList al = new System.Collections.ArrayList();

        //    System.Data.DataTable newdt = GenerateOperationColumn();
        //    if (dt != null && dt.Rows.Count > 0)
        //    {
        //        PIModel model = new PIModel();
        //        for (int i = 0; i < dt.Rows.Count; i++)
        //        {                    
        //            paraContidination = dt.Rows[i]["判断条件"].ToString();
        //            alarmPoint= dt.Rows[i]["条件参数"].ToString().Split(',');
        //            for (int j = 0; j < alarmPoint.Length; j++)
        //            {
        //                double piValue = model.GetCurrentValue(alarmPoint[j].Trim(), PIDeclare);
        //                paraContidination = paraContidination.Replace(alarmPoint[j].Trim(), piValue.ToString());

        //            }
        //            MSScriptControl.ScriptControl SC = new MSScriptControl.ScriptControl();
        //            SC.Language = "VBScript";
        //            if (SC.Eval(paraContidination).ToString().ToUpper() == "TRUE")
        //            {
        //                DataRow dr = newdt.NewRow();
        //                dr[0] = dt.Rows[i]["指导意见"];
        //                newdt.Rows.Add(dr);
        //            }
        //        }
        //    }
        //    return newdt;

        //}
        /// <summary>
        /// 更新知识库
        /// </summary>
        /// <param name="id_key"></param>
        public void Update(int id_key)
        {
            string sql = "UPDATE ADMINISTRATOR.T_ALARM_KBS SET 指导意见='" + OperationIdea + "' WHERE ID_KEY=" + id_key;
            DB2Provider.DataLink link = new DB2Provider.DataLink();
            link.Excute(sql);
        }
        /// <summary>
        /// 删除知识库
        /// </summary>
        /// <param name="id_key"></param>
        public void Delete(int id_key)
        {
            string sql = "DELETE FROM ADMINISTRATOR.T_ALARM_KBS WHERE ID_KEY=" + id_key;
            DB2Provider.DataLink link = new DB2Provider.DataLink();
            link.Excute(sql);
        }
        /// <summary>
        /// 添加报警指导意见
        /// </summary>
        public void Insert()
        {
            string sql = "INSERT INTO ADMINISTRATOR.T_ALARM_KBS(报警描述,指导意见) VALUES('" + AlarmDescription + "','" + OperationIdea + "')";
            DB2Provider.DataLink link = new DB2Provider.DataLink();
            link.Excute(sql);
        }
    }
}
